﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

namespace Xejen.Logger.Log4Net
{
    /// <summary>
    /// 提供log4net日志配置服务的实现
    /// </summary>
    public class Log4NetConfigurationService : ILogConfigurationService
    {
        private readonly string _configFilePath;

        /// <summary>
        /// <inheritdoc cref="Log4NetConfigurationService"/>
        /// </summary>
        /// <param name="configFilePath">日志配置文件路径</param>
        public Log4NetConfigurationService(string configFilePath = "log4net.config")
        {
            _configFilePath = configFilePath;
        }

        /// <inheritdoc/>
        public void Configure()
        {
            if (File.Exists(_configFilePath))
            {
                log4net.Config.XmlConfigurator.Configure(new FileInfo(_configFilePath));
            }
            else
            {
                throw new FileNotFoundException($"Log4Net 配置文件未找到: {_configFilePath}");
            }
        }
    }
}
